﻿<UserControl x:Class="Sasa.QualityTools.CodeAnalysis.FxCopIntegrator.Views.CodeInspectionResultContent"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:local.views="clr-namespace:Sasa.QualityTools.CodeAnalysis.FxCopIntegrator.Views"
             xmlns:local.converters="clr-namespace:Sasa.QualityTools.CodeAnalysis.FxCopIntegrator.Views.Converters"
             xmlns:local.controls="clr-namespace:Sasa.QualityTools.CodeAnalysis.FxCopIntegrator.Views.Controls"
             x:Name="this"
             mc:Ignorable="d" 
             d:DesignHeight="300"
             d:DesignWidth="600">
    <UserControl.Resources>
        <local.converters:DoubleToDataGridLengthConverter x:Key="doubleToDataGridLengthConverter"/>
    </UserControl.Resources>
    <Grid Name="layoutRoot" MinWidth="500" FocusManager.FocusedElement="{Binding ElementName=resultDataGrid}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <local.controls:ToolBar Grid.Row="0"/>
        <DataGrid Name="resultDataGrid" Grid.Row="1" ItemsSource="{Binding CurrentPageRows}" IsSynchronizedWithCurrentItem="True" IsReadOnly="True" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" CanUserSortColumns="True" HorizontalGridLinesBrush="LightGray" VerticalGridLinesBrush="LightGray" Sorting="OnSortRows">
            <DataGrid.Resources>
                <Style x:Key="cellStyle" TargetType="TextBlock">
                    <Setter Property="TextWrapping" Value="WrapWithOverflow"/>
                    <Setter Property="Margin" Value="2"/>
                    <Setter Property="VerticalAlignment" Value="Center"/>
                </Style>
                <BooleanToVisibilityConverter x:Key="booleanToVisibilityConverter"/>
            </DataGrid.Resources>
            <DataGrid.ContextMenu>
                <ContextMenu>
                    <MenuItem Header="Show Columns">
                        <MenuItem Header="Check Id" IsCheckable="True" IsChecked="{Binding Grid.CheckId.IsVisible}"/>
                        <MenuItem Header="Category" IsCheckable="True" IsChecked="{Binding Grid.Category.IsVisible}"/>
                        <MenuItem Header="Project" IsCheckable="True" IsChecked="{Binding Grid.Project.IsVisible}"/>
                        <MenuItem Header="File" IsCheckable="True" IsChecked="{Binding Grid.File.IsVisible}"/>
                        <MenuItem Header="Message" IsCheckable="True" IsChecked="{Binding Grid.Message.IsVisible}"/>
                    </MenuItem>
                    <MenuItem Header="Reset Columns" Click="OnResetColumns"/>
                </ContextMenu>
            </DataGrid.ContextMenu>
            <DataGrid.ItemContainerStyle>
                <Style TargetType="DataGridRow">
                    <EventSetter Event="MouseDoubleClick" Handler="OnProblemDoubleClicked" />
                </Style>
            </DataGrid.ItemContainerStyle>
            <DataGrid.Columns>
                <DataGridTemplateColumn x:Name="kindColumn" Header="" IsReadOnly="True" SortMemberPath="Kind" CanUserResize="False" CanUserReorder="False" Width="25">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Image Margin="5">
                                <Image.Style>
                                    <Style TargetType="Image">
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding Kind}" Value="Target">
                                                <Setter Property="Source" Value="pack://application:,,,/Sasa.QualityTools.CodeAnalysis.FxCopIntegrator;component/Resources/Assembly.png"/>
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding Kind}" Value="Module">
                                                <Setter Property="Source" Value="pack://application:,,,/Sasa.QualityTools.CodeAnalysis.FxCopIntegrator;component/Resources/Assembly.png"/>
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding Kind}" Value="Namespace">
                                                <Setter Property="Source" Value="pack://application:,,,/Sasa.QualityTools.CodeAnalysis.FxCopIntegrator;component/Resources/Namespace.png"/>
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding Kind}" Value="Resource">
                                                <Setter Property="Source" Value="pack://application:,,,/Sasa.QualityTools.CodeAnalysis.FxCopIntegrator;component/Resources/Resource.png"/>
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding Kind}" Value="Class">
                                                <Setter Property="Source" Value="pack://application:,,,/Sasa.QualityTools.CodeAnalysis.FxCopIntegrator;component/Resources/Class.png"/>
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding Kind}" Value="Delegate">
                                                <Setter Property="Source" Value="pack://application:,,,/Sasa.QualityTools.CodeAnalysis.FxCopIntegrator;component/Resources/Delegate.png"/>
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding Kind}" Value="Enum">
                                                <Setter Property="Source" Value="pack://application:,,,/Sasa.QualityTools.CodeAnalysis.FxCopIntegrator;component/Resources/Enum.png"/>
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding Kind}" Value="Interface">
                                                <Setter Property="Source" Value="pack://application:,,,/Sasa.QualityTools.CodeAnalysis.FxCopIntegrator;component/Resources/Interface.png"/>
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding Kind}" Value="Struct">
                                                <Setter Property="Source" Value="pack://application:,,,/Sasa.QualityTools.CodeAnalysis.FxCopIntegrator;component/Resources/Struct.png"/>
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding Kind}" Value="Constructor">
                                                <Setter Property="Source" Value="pack://application:,,,/Sasa.QualityTools.CodeAnalysis.FxCopIntegrator;component/Resources/Method.png"/>
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding Kind}" Value="Event">
                                                <Setter Property="Source" Value="pack://application:,,,/Sasa.QualityTools.CodeAnalysis.FxCopIntegrator;component/Resources/Event.png"/>
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding Kind}" Value="Field">
                                                <Setter Property="Source" Value="pack://application:,,,/Sasa.QualityTools.CodeAnalysis.FxCopIntegrator;component/Resources/Field.png"/>
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding Kind}" Value="Method">
                                                <Setter Property="Source" Value="pack://application:,,,/Sasa.QualityTools.CodeAnalysis.FxCopIntegrator;component/Resources/Method.png"/>
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding Kind}" Value="Property">
                                                <Setter Property="Source" Value="pack://application:,,,/Sasa.QualityTools.CodeAnalysis.FxCopIntegrator;component/Resources/Property.png"/>
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </Image.Style>
                            </Image>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTemplateColumn x:Name="checkIdColumn" Header="Check Id" IsReadOnly="True" SortMemberPath="CheckId"
                                        Width="{Binding (FrameworkElement.DataContext).Grid.CheckId.Width, RelativeSource={RelativeSource Self}, Converter={StaticResource doubleToDataGridLengthConverter}, Mode=TwoWay}"
                                        Visibility="{Binding (FrameworkElement.DataContext).Grid.CheckId.IsVisible, RelativeSource={RelativeSource Self}, Converter={StaticResource booleanToVisibilityConverter}}">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding CheckId}" Style="{StaticResource cellStyle}"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTemplateColumn x:Name="categoryColumn" Header="Category" IsReadOnly="True" SortMemberPath="Category"
                                        Width="{Binding (FrameworkElement.DataContext).Grid.Category.Width, RelativeSource={RelativeSource Self}, Converter={StaticResource doubleToDataGridLengthConverter}, Mode=TwoWay}"
                                        Visibility="{Binding (FrameworkElement.DataContext).Grid.Category.IsVisible, RelativeSource={RelativeSource Self}, Converter={StaticResource booleanToVisibilityConverter}}">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Category}" Style="{StaticResource cellStyle}"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTemplateColumn x:Name="projectColumn" Header="Project" IsReadOnly="True" SortMemberPath="ProjectName"
                                        Width="{Binding (FrameworkElement.DataContext).Grid.Project.Width, RelativeSource={RelativeSource Self}, Converter={StaticResource doubleToDataGridLengthConverter}, Mode=TwoWay}"
                                        Visibility="{Binding (FrameworkElement.DataContext).Grid.Project.IsVisible, RelativeSource={RelativeSource Self}, Converter={StaticResource booleanToVisibilityConverter}}">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding ProjectName}" Style="{StaticResource cellStyle}"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTemplateColumn x:Name="fileColumn" Header="File" IsReadOnly="True" SortMemberPath="FileName"
                                        Width="{Binding (FrameworkElement.DataContext).Grid.File.Width, RelativeSource={RelativeSource Self}, Converter={StaticResource doubleToDataGridLengthConverter}, Mode=TwoWay}"
                                        Visibility="{Binding (FrameworkElement.DataContext).Grid.File.IsVisible, RelativeSource={RelativeSource Self}, Converter={StaticResource booleanToVisibilityConverter}}">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding FileName}" Style="{StaticResource cellStyle}"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTemplateColumn x:Name="messageColumn" Header="Message" IsReadOnly="True" SortMemberPath="Message"
                                        Width="{Binding (FrameworkElement.DataContext).Grid.Message.Width, RelativeSource={RelativeSource Self}, Converter={StaticResource doubleToDataGridLengthConverter}, Mode=TwoWay}"
                                        Visibility="{Binding (FrameworkElement.DataContext).Grid.Message.IsVisible, RelativeSource={RelativeSource Self}, Converter={StaticResource booleanToVisibilityConverter}}">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Message}" Style="{StaticResource cellStyle}"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
            </DataGrid.Columns>
        </DataGrid>
        <Grid Grid.Row="2" Margin="5">
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <TextBlock Grid.Column="0" VerticalAlignment="Center">
                <TextBlock.Text>
                    <MultiBinding StringFormat="{}{0} problems matched (total {1} problems)">
                        <Binding Path="Count"/>
                        <Binding Path="Rows.Count"/>
                    </MultiBinding>
                </TextBlock.Text>
            </TextBlock>
            <local.controls:Pager Grid.Column="1"/>
        </Grid>
    </Grid>
</UserControl>
